package org.test.mailSender;

import java.util.Date;
import java.util.Properties;

import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;



public class MailSend {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		try {
			execute();
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
	}

	public static void execute() throws Exception {

		Properties props = System.getProperties();
		props.put("mail.smtp.host", "smtp.163.com");
		props.put("mail.smtp.auth", "true");
		Session session = Session.getDefaultInstance(props, null);
		MimeMessage msg = new MimeMessage(session);

		InternetAddress toList[] = InternetAddress.parse("445436848@qq.com,1814779971@qq.com",
				false);
		msg.addRecipients(MimeMessage.RecipientType.TO, toList);

		InternetAddress fromAddress = new InternetAddress("guoming.1989@163.com");
		msg.setFrom(fromAddress);
		msg.setSentDate(new Date());

		msg.setSubject("mail", "text/html;charset=utf-8");

		String txt = "你妹啊?";
		msg.setText(txt, "utf-8");

		try {
			Transport transport = session.getTransport("smtp");
			transport.connect("smtp.163.com", "guoming.1989", "guoming123");//***这里加上密码
			transport.sendMessage(msg, toList);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
